﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufArrangementAreaContent.h"

namespace gnuf {

    class QtWelcomePanel;

    enum class EWelcomeButtonType {
        eKnowMore,
        eNewDocument,
        eOpenLocalDocument,
        eOpenWorkspace,
        eLogin
    };

    struct WelcomeButtonInfo {
        WelcomeButtonInfo(const std::wstring & cp, const std::wstring & ic, EWelcomeButtonType type) 
            : caption(cp), icon(ic), btnType(type) {}
        std::wstring caption, icon; 
        gcmp::Any userData;
        EWelcomeButtonType btnType;
    };

    class GNUF_BASE_EXPORT WelcomePanel final
        : public ArrangementAreaContent
    {
    public:
        explicit WelcomePanel();
        ~WelcomePanel();
        
        inline void setApplicationIcon(const std::wstring & v) { m_applicationIcon = v; }
        inline const std::wstring & applicatonIcon() const { return m_applicationIcon; }

        inline void setWhatsThis(const std::wstring & v) { m_whatsThis = v; }
        inline const std::wstring & whatsThis() const { return m_whatsThis; }

        inline void setProductGoal(const std::wstring & v) { m_productGoal = v; }
        inline const std::wstring & productGoal() const { return m_productGoal; }

        inline void setLoginTitle(const std::wstring& v) { m_loginTitle = v; }
        inline const std::wstring& loginTitle() const { return m_loginTitle; }

        inline void setLoginSubTitle(const std::wstring& v) { m_loginSubTitle = v; }
        inline const std::wstring& loginSubTitle() const { return m_loginSubTitle; }

        inline void setButtonKnowMore(
            const std::wstring & caption, 
            const std::wstring & icon, 
            const gcmp::Any & userData)
        {
            m_knowMore.caption = caption;
            m_knowMore.icon = icon;
            m_knowMore.userData = userData;
        }
        inline const WelcomePanel::WelcomeButtonInfo & buttonKnowMore() const { return m_knowMore; }

        inline void setButtonNewDocument(
            const std::wstring & caption, 
            const std::wstring & icon, 
            const gcmp::Any & userData)
        {
            m_newDocument.caption = caption;
            m_newDocument.icon = icon;
            m_newDocument.userData = userData;
        }
        inline const WelcomePanel::WelcomeButtonInfo & buttonNewDocument() const { return m_newDocument; }

        inline void setButtonOpenLocalDocument(
            const std::wstring & caption,
            const std::wstring & icon,
            const gcmp::Any & userData)
        {
            m_openLocalDocument.caption = caption;
            m_openLocalDocument.icon = icon;
            m_openLocalDocument.userData = userData;
        }
        inline const WelcomePanel::WelcomeButtonInfo & buttonOpenLocalDocument() const { return m_openLocalDocument; }

        inline void setButtonOpenWorkspace(
            const std::wstring & caption, 
            const std::wstring & icon, 
            const gcmp::Any & userData)
        {
            m_openWorkspace.caption = caption; 
            m_openWorkspace.icon = icon; 
            m_openWorkspace.userData = userData;
        }
        inline const WelcomePanel::WelcomeButtonInfo & buttonOpenWorkspace() const { return m_openWorkspace; }

        inline void setButtonLogin(
            const std::wstring & caption, 
            const std::wstring & icon, 
            const gcmp::Any & userData)
        {
            m_login.caption = caption;
            m_login.icon = icon;
            m_login.userData = userData;
        }
        inline const WelcomePanel::WelcomeButtonInfo & buttonLogin() const { return m_login; }

        void refreshLoginWidget();

    protected:
        // Inherits from ArrangementAreaContent...
        virtual QWidget * qtWidget() override;
        virtual void onPostVisibilityChanged() override;
        virtual void onPostConnectedWithArrangementArea() override;
        virtual void onPreDisconnectedFromArrangementArea() override;
        virtual void onPostGeometryChanged() override;

    private:
        std::wstring m_applicationIcon, m_whatsThis, m_productGoal, m_loginTitle,m_loginSubTitle;
        WelcomePanel::WelcomeButtonInfo m_knowMore, m_newDocument, m_openLocalDocument, m_openWorkspace, m_login;

        gcmp::OwnerPtr< QtWelcomePanel > m_qtWelcomePanel;
    };

}
